package com.xlhj.rabbit.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Author: caijliu
 * @Date: 04/09/2021 14:24
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@RestController
@RequestMapping("/ttl")
public class TtlQueueProducerController {

    private static final String TTL_QUEUE_EXCHANGE = "ttl-queue-exchange";
    private static final String TTL_QUEUE_A_ROUT_KEY = "ttl_queue-A-routing-key";
    private static final String TTL_QUEUE_B_ROUT_KEY = "ttl_queue-B-routing-key";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("sendMessage/{message}")
    public void sendMessage(@PathVariable String message) {
        String uuid1 = UUID.randomUUID().toString();
        CorrelationData correlationData1 = new CorrelationData(uuid1);
        rabbitTemplate.convertAndSend(TTL_QUEUE_EXCHANGE, TTL_QUEUE_A_ROUT_KEY, "ttl消息：" + message + "为10s", correlationData1);
        String uuid2 = UUID.randomUUID().toString();
        CorrelationData correlationData2 = new CorrelationData(uuid2);
        rabbitTemplate.convertAndSend(TTL_QUEUE_EXCHANGE, TTL_QUEUE_B_ROUT_KEY, "ttl消息：" + message + "为40s", correlationData2);
    }
}
